<?php


namespace App\backend\services;


use App\backend\models\AreaModel;
use App\common\models\Coupon;
use App\common\models\CouponStore;
use App\common\models\CouponUseLog;
use App\common\services\BaseServices;

class SubsidyServices extends BaseServices
{

    /**
     * 获取 - 通用卡券列表
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function getLists($data)
    {

        $page = !isset($data['page']) ? 1 : $data['page'];
        unset($data['page']);
        $limit = !isset($data['limit']) ? 10 : $data['limit'];
        unset($data['limit']);

        $where_data = [];

        if (isset($data['name']) && !empty($data['name'])) {
            $where_data[] = ['name', 'LIKE', '%' . $data['name'] . '%'];
        }
        if (isset($data['coupon_type']) && !empty($data['coupon_type'])) {
            $where_data[] = ['coupon_type', '=', $data['coupon_type']];
        }
        if (isset($data['coupon_type']) && !empty($data['coupon_type'])) {
            $where_data[] = ['coupon_type', '=', $data['coupon_type']];
        }
        if (isset($data['city']) && !empty($data['city'])) {
            $where_data[] = [function ($query) use ($data) {$query->whereRaw('FIND_IN_SET(?,city)',$data['city']);}];
        }
        if (isset($data['start_time']) && !empty($data['start_time'])) {
            $where_data[] = ['use_time_start', '>=', strtotime($data['start_time'])];
        }
        if (isset($data['end_time']) && !empty($data['end_time'])) {
            $where_data[] = ['use_time_end', '<=', strtotime($data['end_time'])];
        }
        $select = ['id', 'name', 'city', 'coupon_type', 'category', 'shop_id', 'remitted_money', 'subsidy_type', 'subsidy_money', 'use_time_start', 'use_time_end', 'created_at', 'stock'];
        $list = Coupon::listed($page, $limit, $where_data, $select);
        foreach($list['data'] as $v){
            $v->use_time_start = empty($v->use_time_start) ? '' : date('Y-m-d H:i:s', $v->use_time_start);
            $v->use_time_end = empty($v->use_time_end) ? '' : date('Y-m-d H:i:s', $v->use_time_end);

            $city = explode(',', $v->city);
            $cityName = [];
            foreach ($city as $city_id) {
                $cityName[] = AreaModel::cityInfo($city_id);
            }
            $v->city_name = $cityName;

            //购买数量 已用数量
            $v->send_number = CouponUseLog::getUseNumber(['coupon_id' => $v->id]);
            $v->use_number = CouponUseLog::getUseNumber(['coupon_id' => $v->id, 'is_use' => CouponUseLog::IS_USE]);

            //补贴金额
            if ($v->subsidy_type == 1) {
                $v->subsidy_money = 0;
            } elseif ($v->subsidy_type == 2) {
                $v->subsidy_money = $v->subsidy_money * $v->use_number;
            } else {
                $v->subsidy_money = $v->remitted_money * $v->use_number;
            }

            //保证金
            $v->earnest_money = $v->remitted_money * $v->stock;

            //需退款
            $v->refund_money = $v->remitted_money * ($v->stock - $v->send_number);
        }

        return $list;
    }

    /**
     * 获取 - 专用卡券列表
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function getDedicatedCouponList($data)
    {

        $page = !isset($data['page']) ? 1 : $data['page'];
        unset($data['page']);
        $limit = !isset($data['limit']) ? 10 : $data['limit'];
        unset($data['limit']);

        $where_data = [];
        $where_data[] = ['type', '=', Coupon::TYPE_DEDICATED];
        $where_data[] = ['is_deleted', '=', Coupon::NOT_DELETE];
        if (isset($data['name']) && !empty($data['name'])) {
            $where_data[] = ['name', 'LIKE', '%' . $data['name'] . '%'];
        }
        if (isset($data['shop_id']) && !empty($data['shop_id'])) {
            $where_data[] = ['shop_id', '=', $data['shop_id']];
        }
        if (isset($data['city']) && !empty($data['city'])) {
            $where_data[] = ['city', '=', $data['city']];
        }
        if (isset($data['start_time']) && !empty($data['start_time'])) {
            $where_data[] = ['use_time_start', '>=', strtotime($data['start_time'])];
        }
        if (isset($data['end_time']) && !empty($data['end_time'])) {
            $where_data[] = ['use_time_end', '<=', strtotime($data['end_time'])];
        }
        $select = ['id', 'name', 'city', 'coupon_type', 'category', 'shop_id', 'remitted_money', 'subsidy_type', 'subsidy_money', 'use_time_start', 'use_time_end', 'created_at', 'stock'];
        $list = Coupon::listed($page, $limit, $where_data, $select);
        //门店名称
        //取出所以商户id
        $shop_ids = array_column($list['data'], 'shop_id');
        $shop_ids = implode(',', $shop_ids);
        $shop_ids = explode(',', $shop_ids);
        $shopNameArr = CouponUseLog::getShopName($shop_ids);
        $k = array_column($shopNameArr, 'id');
        $shopNameArr = array_combine($k, $shopNameArr);
        foreach($list['data'] as $v){
            $v->use_time_start = empty($v->use_time_start) ? '' : date('Y-m-d H:i:s', $v->use_time_start);
            $v->use_time_end = empty($v->use_time_end) ? '' : date('Y-m-d H:i:s', $v->use_time_end);
            $v->created_at = empty($v->created_at) ? '' : date('Y-m-d H:i:s', $v->created_at);

            $city = explode(',', $v->city);
            $cityName = [];
            foreach ($city as $city_id) {
                $cityName[] = AreaModel::cityInfo($city_id);
            }
            $v->city_name = $cityName;

            $shop = explode(',', $v->shop_id);
            $shopName = [];
            foreach($shop as $shop_id){
                $shopName[] = !empty($shopNameArr[$shop_id]) ? $shopNameArr[$shop_id]['name'] : '暂无数据';
            }
            $v->shop_name = $shopName;

            //购买数量 已用数量
            $v->send_number = CouponUseLog::getUseNumber(['coupon_id' => $v->id]);
            $v->use_number = CouponUseLog::getUseNumber(['coupon_id' => $v->id, 'is_use' => CouponUseLog::IS_USE]);
        }
        return $list;
    }

    /**
     * 获取 - 通用卡券详情
     *
     * @param $data
     * @return array
     */
    public static function getUniversalCouponDetail($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id'] = !empty($data['id']) ? $data['id'] : 0;
        $data['type'] = Coupon::TYPE_UNIVERSAL;
        $data['is_deleted'] = Coupon::NOT_DELETE;

        $list = Coupon::detail($data);
        if (empty($list) && $list == false) {
            return [];
        }
        //处理数据
        $returnData['id'] = $list->id;
        $returnData['name'] = $list->name;
        $returnData['city'] = $list->city;
        $city = explode(',', $list->city);
        foreach ($city as $city_id) {
            $cityName[] = AreaModel::cityInfo($city_id);
        }
        $returnData['city_name'] = $cityName;//
        $returnData['coupon_type'] = $list->coupon_type;
        $returnData['category'] = $list->category;
        $returnData['category_name'] = $list->category;//
        $returnData['satisfy_money'] = $list->satisfy_money;
        $returnData['remitted_money'] = $list->remitted_money;
        $returnData['stock'] = $list->stock;
        $returnData['subsidy_type'] = $list->subsidy_type;
        $returnData['subsidy_money'] = $list->subsidy_money;
        $returnData['get_type'] = $list->get_type;
        $returnData['price'] = $list->price;
        $returnData['get_time_type'] = $list->get_time_type;
        $returnData['get_time_start'] = empty($list->get_time_start) ? '' : date('Y-m-d H:i', $list->get_time_start);
        $returnData['get_time_end'] = empty($list->get_time_end) ? '' : date('Y-m-d H:i', $list->get_time_end);
        $returnData['use_time_start'] = empty($list->use_time_start) ? '' : date('Y-m-d H:i', $list->use_time_start);
        $returnData['use_time_end'] = empty($list->use_time_end) ? '' : date('Y-m-d H:i', $list->use_time_end);
        $returnData['get_limit_max'] = $list->get_limit_max;
        $returnData['is_open'] = $list->is_open;
        $returnData['use_limit_max'] = $list->use_limit_max;
        $returnData['content'] = $list->content;

        return $returnData;
    }

    /**
     * 获取 - 专用卡券详情
     *
     * @param $data
     * @return array
     */
    public static function getDedicatedCouponDetail($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id'] = !empty($data['id']) ? $data['id'] : 0;
        $data['type'] = Coupon::TYPE_DEDICATED;
        $data['is_deleted'] = Coupon::NOT_DELETE;

        $list = Coupon::detail($data);

        //处理数据
        $returnData['id'] = $list->id;
        $returnData['name'] = $list->name;
        $returnData['city'] = $list->city;
        $city = explode(',', $list->city);
        foreach ($city as $city_id) {
            $cityName[] = AreaModel::cityInfo($city_id);
        }
        $returnData['city_name'] = $cityName;//
        $returnData['coupon_type'] = $list->coupon_type;
        $returnData['shop_id'] = $list->shop_id;

        $shop = explode(',', $list->shop_id);
        $shopNameArr = CouponUseLog::getShopName($shop);
        $k = array_column($shopNameArr, 'id');
        $shopNameArr = array_combine($k, $shopNameArr);
        $shopName = [];
        foreach($shop as $shop_id){
            $shopName[] = !empty($shopNameArr[$shop_id]) ? $shopNameArr[$shop_id]['name'] : '暂无数据';
        }
        $returnData['shop_name'] = $shopName;//

        $returnData['satisfy_money'] = $list->satisfy_money;
        $returnData['remitted_money'] = $list->remitted_money;
        $returnData['stock'] = $list->stock;
        $returnData['get_type'] = $list->get_type;
        $returnData['price'] = $list->price;
        $returnData['confine_type'] = $list->confine_type;
        $returnData['confine_id'] = $list->confine_id;

        $confineIds = explode(',', $list->confine_id);
        switch($list->confine_type) {
            case 1:
                $returnData['confine_name'] = ['全场通用'];
                break;
            case 2: //商品
                $goodsName = CouponUseLog::getGoodsName($confineIds);
                $returnData['confine_name'] = array_column($goodsName, 'name');
                break;
            case 3: //分类
                $categoryName = CouponUseLog::getCategoryName($confineIds);
                $returnData['confine_name'] = array_column($categoryName, 'name');
                break;
            case 4: //分组
                $groupName = CouponUseLog::getGroupName($confineIds);
                $returnData['confine_name'] = array_column($groupName, 'name');
                break;
            default:
                $returnData['confine_name'] = [];
                break;
        }

        $returnData['except_type'] = $list->except_type;
        $returnData['except_id'] = $list->except_id;


        $exceptIds = explode(',', $list->except_id);
        switch($list->confine_type) {
            case 1:
                $returnData['except_name'] = ['全场通用'];
                break;
            case 2: //商品
                $goodsName = CouponUseLog::getGoodsName($exceptIds);
                $returnData['except_name'] = array_column($goodsName, 'name');
                break;
            case 3: //分类
                $categoryName = CouponUseLog::getCategoryName($exceptIds);
                $returnData['except_name'] = array_column($categoryName, 'name');
                break;
            case 4: //分组
                $groupName = CouponUseLog::getGroupName($exceptIds);
                $returnData['except_name'] = array_column($groupName, 'name');
                break;
            default:
                $returnData['except_name'] = [];
                break;
        }

        $returnData['get_time_type'] = $list->get_time_type;
        $returnData['get_time_start'] = empty($list->get_time_start) ? '' : date('Y-m-d H:i', $list->get_time_start);
        $returnData['get_time_end'] = empty($list->get_time_end) ? '' : date('Y-m-d H:i', $list->get_time_end);
        $returnData['use_time_start'] = empty($list->use_time_start) ? '' : date('Y-m-d H:i', $list->use_time_start);
        $returnData['use_time_end'] = empty($list->use_time_end) ? '' : date('Y-m-d H:i', $list->use_time_end);
        $returnData['get_limit_max'] = $list->get_limit_max;
        $returnData['is_open'] = $list->is_open;
        $returnData['use_limit_max'] = $list->use_limit_max;
        $returnData['content'] = $list->content;

        return $returnData;
    }

    /**
     * 添加/编辑 - 通用券
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function modifyUniversalCoupon($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        // 可领取时间方式 1时间段
        if ($data['get_time_type'] == 1) {
            if ($data['get_time_start'] == false || $data['get_time_end'] == false) {
                errorJson('可领取时间段必须填写!', []);
            }
            $data['get_time_start'] = strtotime($data['get_time_start'].' 00:00:00');
            $data['get_time_end'] = strtotime($data['get_time_end'].' 23:59:59');
        }

        $data['type'] = 1;
        $data['use_time_start'] = strtotime($data['use_time_start'].' 00:00:00');
        $data['use_time_end'] = strtotime($data['use_time_end'].' 23:59:59');

        $id = !empty($data['id']) ? $data['id'] : 0;
        unset($data['id']);

        if ($id) {
            $data['updated_at'] = time();
            $list = Coupon::updatedData($id, $data);
        } else {
            $data['created_at'] = time();
            $list = Coupon::insertData($data);
        }

        return $list;
    }

    /**
     * 添加/编辑 - 专用券
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function modifyDedicatedCoupon($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        // 可领取时间方式 1时间段
        if ($data['get_time_type'] == 1) {
            if ($data['get_time_start'] == false || $data['get_time_end'] == false) {
                errorJson('可领取时间段必须填写!', []);
            }
            $data['get_time_start'] = strtotime($data['get_time_start'].' 00:00:00');
            $data['get_time_end'] = strtotime($data['get_time_end'].' 23:59:59');
        }

        $data['type'] = 2;
        $data['use_time_start'] = strtotime($data['use_time_start'].' 00:00:00');
        $data['use_time_end'] = strtotime($data['use_time_end'].' 23:59:59');

        $id = !empty($data['id']) ? $data['id'] : 0;
        unset($data['id']);

        if ($id) {
            $data['updated_at'] = time();
            $list = Coupon::updatedData($id, $data);
        } else {
            $data['created_at'] = time();
            $list = Coupon::insertData($data);
        }

        return $list;
    }

    /**
     * 删除 - 卡券
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function updateGoodStatus($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id'] = !empty($data['id']) ? $data['id'] : 0;
        $update_data['is_deleted'] = !empty($data['is_deleted']) ? $data['is_deleted'] : Coupon::IS_DELETE;
        unset($data['is_deleted']);
        $update_data['deleted_at'] = time();

        $list = Coupon::deleteds($data, $update_data);
        return $list;
    }

    /**
     * 发卡券
     *
     * @param $data
     */
    public static function sendCoupon($data)
    {
        $member_id = explode(',', $data['member_id']);
        $number = $data['number'];
        if (empty($member_id) || $number <= 0) {
            return [];
        }
        $coupon_id = $data['coupon_id'];

        //获取卡券信息
        $couponDetail = Coupon::detail(['id' => $coupon_id]);

        //判断卡券发放数量
        if ($couponDetail->stock > 0) {
            $useNumber = CouponUseLog::getUseNumber(['coupon_id' => $coupon_id]);
            if (($useNumber + ($number * count($member_id))) > $couponDetail->stock) {
                return ['msg' => '发券数量超过库存'];
            }
        }

        foreach ($member_id as $v) {
            $addData = [];
            if ($couponDetail->get_limit_max > 0) {
                $memberUseNumber = CouponUseLog::getUseNumber(['coupon_id' => $coupon_id, 'member_id' => $v]);
                if (($memberUseNumber + $number) > $couponDetail->get_limit_max) {
                    return ['msg' => '发券数量超过单人限领数量'];
                }
            }
            for ($i = 0; $i < $number; $i++) {
                $addData[] = [
                    'coupon_id' => $coupon_id,
                    'type' => $couponDetail->type,
                    'get_type' => 1,
                    'use_time_end' => $couponDetail->use_time_end,
                    'member_id' => $v,
                    'created_at' => time()
                ];
            }
            $list = CouponUseLog::insertData($addData);
        }
        return $list;
    }

    /**
     * 使用记录
     *
     * @param $data
     * @return array
     */
    public static function getUseLog($data){

        $page = !isset($data['page']) ? 1 : $data['page'];
        unset($data['page']);
        $limit = !isset($data['limit']) ? 10 : $data['limit'];
        unset($data['limit']);

        $where_data = [];
        if (isset($data['name']) && !empty($data['name'])) {
            //先找出符合要求的Coupon_id
            $couponIds = Coupon::getCouponIds([['name', 'LIKE', '%' . $data['name'] . '%']]);
            $couponIds = array_column($couponIds,'id');
            $where_data[] = [function($query)use($couponIds){$query->whereIn('coupon_id',$couponIds);}];
        }
        if (isset($data['member_id']) && !empty($data['member_id'])) {
            //先找出符合要求的member_id
            $memberIds = CouponUseLog::getMemberIds($data['member_id']);
            $memberIds = array_column($memberIds,'id');
            $where_data[] = [function($query)use($memberIds){$query->whereIn('member_id',$memberIds);}];
        }
        if (isset($data['start_time']) && !empty($data['start_time'])) {
            $where_data[] = ['verification_at', '>=', strtotime($data['start_time'])];
        }
        if (isset($data['end_time']) && !empty($data['end_time'])) {
            $where_data[] = ['verification_at', '<=', strtotime($data['start_time'])];
        }

        $list = CouponUseLog::listed($page, $limit, $where_data);
        //取出所以卡券id
        $coupon_ids = array_column($list['data'], 'coupon_id');
        $couponName = Coupon::getCouponName($coupon_ids);
        $k = array_column($couponName, 'id');
        $couponName = array_combine($k, $couponName);
        //取出所以会员id
        $member_ids = array_column($list['data'], 'member_id');
        $memberName = CouponUseLog::getMemberName($member_ids);
        $k = array_column($memberName, 'id');
        $memberName = array_combine($k, $memberName);
        //取出所以商户id
        $shop_ids = array_column($list['data'], 'shop_id');
        $shopName = CouponUseLog::getShopName($shop_ids);
        $k = array_column($shopName, 'id');
        $shopName = array_combine($k, $shopName);

        foreach($list['data'] as $v){
            $v->coupon_name = !empty($couponName[$v->coupon_id]) ? $couponName[$v->coupon_id]['name'] : '';
            $v->member_name = !empty($memberName[$v->member_id]) ? $memberName[$v->member_id]['name'] : '';
            $v->shop_name = !empty($shopName[$v->shop_id]) ? $shopName[$v->shop_id]['name'] : '';
            $v->verification_at = $v->verification_at ? date('Y-m-d H:i:s', $v->verification_at) : '';
        }

        return $list;
    }

    /**
     * 获取 - 商用卡券列表
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function getStoreCouponLists($data)
    {

        $page = !isset($data['page']) ? 1 : $data['page'];
        unset($data['page']);
        $limit = !isset($data['limit']) ? 10 : $data['limit'];
        unset($data['limit']);

        $where_data = [];
        $where_data[] = ['type', '=', Coupon::TYPE_STORE];
        $where_data[] = ['is_deleted', '=', Coupon::NOT_DELETE];
        if (isset($data['name']) && !empty($data['name'])) {
            $where_data[] = ['name', 'LIKE', '%' . $data['name'] . '%'];
        }
        if (isset($data['shop_id']) && !empty($data['shop_id'])) {
            $where_data[] = ['shop_id', '=', $data['shop_id']];
        }
        //限用圈子搜索
        if (isset($data['circle_id']) && !empty($data['circle_id'])) {
            $circleId = $data['circle_id'];
            $where_data[] = ['store_confine_type', '=', 5];
            $where_data[] = [function ($query) use ($circleId) {
                $query->whereRaw('FIND_IN_SET(?,store_confine_id)',$circleId);
            }];
        }
        //限用门店分类搜索
        if (isset($data['category_id']) && !empty($data['category_id'])) {
            $categoryId = $data['category_id'];
            $where_data[] = ['store_confine_type', '=', 6];
            $where_data[] = [function ($query) use ($categoryId) {
                $query->whereRaw('FIND_IN_SET(?,store_confine_id)',$categoryId);
            }];
        }
        //限用门店搜索
        if (isset($data['store_id']) && !empty($data['store_id'])) {
            $storeId = $data['store_id'];
            $where_data[] = ['store_confine_type', '=', 4];
            $where_data[] = [function ($query) use ($storeId) {
                $query->whereRaw('FIND_IN_SET(?,store_confine_id)',$storeId);
            }];
        }

        if (isset($data['start_time']) && !empty($data['start_time'])) {
            $where_data[] = ['use_time_start', '>=', strtotime($data['start_time'])];
        }
        if (isset($data['end_time']) && !empty($data['end_time'])) {
            $where_data[] = ['use_time_end', '<=', strtotime($data['end_time'])];
        }

        $select = ['id', 'name', 'shop_id', 'price', 'remitted_money', 'use_time_start', 'use_time_end', 'created_at', 'stock', 'store_confine_type', 'store_confine_id'];
        $list = Coupon::listed($page, $limit, $where_data, $select);
        $list = object_to_array($list);
        //门店名称
        //取出所以商户id
        $shop_ids = array_column($list['data'], 'shop_id');
        $shopNameArr = CouponUseLog::getShopName($shop_ids);
        $k = array_column($shopNameArr, 'id');
        $shopNameArr = array_combine($k, $shopNameArr);
        foreach($list['data'] as &$v){
            $v['created_at'] = empty($v['created_at']) ? '' : date('Y-m-d H:i:s', $v['created_at']);
            $v['use_time_start'] = empty($v['use_time_start']) ? '' : date('Y-m-d H:i:s', $v['use_time_start']);
            $v['use_time_end'] = empty($v['use_time_end']) ? '' : date('Y-m-d H:i:s', $v['use_time_end']);

            $v['shop_name'] = !empty($shopNameArr[$v['shop_id']]) ? $shopNameArr[$v['shop_id']]['name'] : '暂无数据';
            //限用圈子，分类，门店
            $circleName = $categoryName = $storeName = [];
            switch($v['store_confine_type']){
                case 3: // 商品分类
                    $ids = explode(',', $v['store_confine_id']);
                    $categoryName = CouponUseLog::getCategoryName($ids);
                    $categoryName = array_column($categoryName, 'name');
                    break;
                case 4: // 限用圈子
                    $ids = explode(',', $v['store_confine_id']);
                    $storeName = CouponUseLog::getShopName($ids);
                    $storeName = array_column($storeName, 'name');
                    break;
                case 5: //限用门店

                    break;
                default:
                    break;
            }
            $v['circle_name'] = empty($circleName) ? '' : $circleName;
            $v['category_name'] = empty($categoryName) ? '' : $categoryName;
            $v['store_name'] = empty($storeName) ? '' : $storeName;

            //购买数量 已用数量
            $v['send_number'] = CouponUseLog::getUseNumber(['coupon_id' => $v['id']]);
            $v['use_number'] = CouponUseLog::getUseNumber(['coupon_id' => $v['id'], 'is_use' => 1]);

            //保证金
            $moneyInfo = CouponStore::getDetail(['coupon_id' => $v['id']]);
            $moneyInfo = object_to_array($moneyInfo);
            //补贴
            $v['subsidy_money'] = $moneyInfo['subsidy_money'] * $v['stock'];
            //保证金
            $v['earnest_money'] = $moneyInfo['money'] * $v['stock'];
            //剩余保证金
            $v['residue_earnest_money'] = $moneyInfo['money'] * ($v['stock'] - $v['send_number']);
        }
        return $list;
    }

    /**
     * 商户券详情
     *
     * @param $data
     * @return array
     */
    public static function getStoreCouponDetail($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id'] = !empty($data['id']) ? $data['id'] : 0;
        $data['type'] = Coupon::TYPE_STORE;
        $data['is_deleted'] = Coupon::NOT_DELETE;
        //获取卡券信息
        $couponDetail = Coupon::detail(['id' => $data['id']]);
        //处理数据
        $returnData['id'] = $couponDetail->id;
        $returnData['name'] = $couponDetail->name;
        $returnData['satisfy_money'] = $couponDetail->satisfy_money;
        $returnData['remitted_money'] = $couponDetail->remitted_money;
        $returnData['stock'] = $couponDetail->stock;
        $returnData['get_type'] = $couponDetail->get_type;
        $returnData['price'] = $couponDetail->price;
        $returnData['get_time_type'] = $couponDetail->get_time_type;
        $returnData['get_time_start'] = empty($couponDetail->get_time_start) ? '' : date('Y-m-d H:i', $couponDetail->get_time_start);
        $returnData['get_time_end'] = empty($couponDetail->get_time_end) ? '' : date('Y-m-d H:i', $couponDetail->get_time_end);
        $returnData['use_time_start'] = empty($couponDetail->use_time_start) ? '' : date('Y-m-d H:i', $couponDetail->use_time_start);
        $returnData['use_time_end'] = empty($couponDetail->use_time_end) ? '' : date('Y-m-d H:i', $couponDetail->use_time_end);
        $returnData['get_limit_max'] = $couponDetail->get_limit_max;
        $returnData['is_open'] = $couponDetail->is_open;
        $returnData['use_limit_max'] = $couponDetail->use_limit_max;
        $returnData['content'] = $couponDetail->content;
        $returnData['store_confine_type'] = $couponDetail->store_confine_type;
        $returnData['store_confine_id'] = $couponDetail->store_confine_id;
        $returnData['use_astrict'] = $couponDetail->use_astrict;

        return $returnData;
    }

    /**
     * 设置停售
     *
     * @param $data
     * @return array
     */
    public static function haltSales($data)
    {
        $where[] = ['coupon_id', '=', $data['id']];
        $update = ['status' => CouponStore::STATUS_HALT_SALE];
        $return  = CouponStore::updatedData($where,$update);
        return $return;
    }
}
